<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
else {
	$userid = $_SESSION['userid'];
}

include_once 'config.php';
$random = rand(1,5);

function getLexid($lexcreated)
{
	
	$userid = $_SESSION['userid'];
	$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die ("Could not execute query");
	$query = "SELECT lexid FROM lexsettings WHERE lexcreated = '$lexcreated' AND userid = '$userid'";
	$result = mysqli_query($con,$query) or die ("Could not get lexid");
	while ($row = mysqli_fetch_array($result))
    {	
		$lexid = $row['lexid'];     
		$_SESSION['lexid'] = $lexid;			 
	 	return $lexid;
}	
}	

function getGReflection($reflectionNo, $choicebank) {
	$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("Could not execute query");
	$reflectionNo = "ref$reflectionNo";
	$query = "SELECT * FROM $reflectionNo WHERE choicebank = $choicebank ORDER BY RAND()";
	$result = mysqli_query($con, $query) or die("Could not get the required reflection guidance");
	while ($row = mysqli_fetch_array($result)) {
	echo("<option value = '" . $row['choicetext'] . "'>" . $row['choicetext'] . "</option>");
	}

}

function getGOutcome($outcomeNo, $choicebank) {
	$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("Could not execute query");
	$outcomeNo = "outcome$outcomeNo";
	$query = "SELECT * FROM $outcomeNo WHERE choicebank = $choicebank ORDER BY RAND()";
	$result = mysqli_query($con, $query) or die("Could not get the required outcome guidance");
	while ($row = mysqli_fetch_array($result)) {
	echo("<option value = '" . $row['choicetext'] . "'>" . $row['choicetext'] . "</option>");
	}

}


function getGRstarter($refid) {
	$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("Could not execute query");
	$query = "SELECT * FROM reflectionStarter";
	$result = mysqli_query($con, $query) or die("Could not get the required reflection starter text");
	while ($row = mysqli_fetch_array($result)) {
	echo "<span>" . $row['startertext'] . "</span>";
	}
}
?>